﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPageContent.master" AutoEventWireup="false" CodeFile="Budget.aspx.vb" Inherits="Budget" %>

<%@ Register src="~/UserControls/OneFilteredDropDownList.ascx" tagname="OneFilteredDropDownList" tagprefix="uc2" %>

<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <link href="Design/EasyAccounting/Buttons.css" rel="stylesheet" type="text/css" />

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeaderPlaceHolder" Runat="Server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">





    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rgBudgetAccounts">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rgBudgetAccounts" LoadingPanelID="RadAjaxLoadingPanel1"/>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="rntbYear">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rtbPrgram" />
                        <telerik:AjaxUpdatedControl ControlID="rtbActivityNum" />
                        <telerik:AjaxUpdatedControl ControlID="rgBudgetAccounts" LoadingPanelID="RadAjaxLoadingPanel1"/>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnSave">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
                        <telerik:AjaxUpdatedControl ControlID="rgBudgetAccounts" LoadingPanelID="RadAjaxLoadingPanel1"/>
                    </UpdatedControls>
                </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Office2010Blue" Transparency="20">
    </telerik:RadAjaxLoadingPanel>

     <telerik:RadWindowManager ID="RadWindowManager1" runat="server">  
     </telerik:RadWindowManager>

     <br /><br />

     <table>
        <tr >
            <td >
                <asp:Label ID="lblManYear" runat="server" SkinID="Mandetory" Text="<%$ Resources:Controls, RequiredValidationText %>" ></asp:Label>
                <asp:Label ID="lblYear" runat="server" meta:ResourceKey="lblYear" ></asp:Label>
            </td>
            <td >
                <telerik:RadNumericTextBox ID="rntbYear" runat="server" Width="170px" MaxLength="4" MaxValue="2200" ValidationGroup="valBudget"
                 IncrementSettings-InterceptArrowKeys="true" IncrementSettings-InterceptMouseWheel="true" AutoPostBack="true" OnTextChanged="Year_TextChanged">
                    <NumberFormat DecimalDigits="0" GroupSizes="4" />
                </telerik:RadNumericTextBox>
                <asp:RequiredFieldValidator ID="rfvrntbYear" runat="server" ControlToValidate="rntbYear" ErrorMessage="<%$ Resources:Controls, ErrorMessage %>" ValidationGroup="valBudget"></asp:RequiredFieldValidator> 
            </td>
        </tr>
        <tr>
            <td >
                <asp:Label ID="lblrtbPrgram" runat="server" meta:ResourceKey="lblrtbPrgram" ></asp:Label>
            </td>
            <td >
                <telerik:RadTextBox ID="rtbPrgram" Width="170px" runat="server" SkinID="rtbSkin" >
                </telerik:RadTextBox>
            </td>
        </tr>
        <tr>
            <td >
                <asp:Label ID="lblActivityNum" runat="server" meta:ResourceKey="lblActivityNum" ></asp:Label>
            </td>
            <td >
                <telerik:RadTextBox ID="rtbActivityNum" Width="170px" runat="server" SkinID="rtbSkin" >
                </telerik:RadTextBox>
            </td>
        </tr>
    </table>

     <br /><br />
     

     <telerik:RadGrid ID="rgBudgetAccounts" DataSourceID="odsBudgetAccounts"
        Width="880px" CellSpacing="0" MasterTableView-Dir="<%$ Resources:SystemResource, HTMLDirectionality %>"
        runat="server" AutoGenerateColumns="False" Skin="Metro" GridLines="None" 
        AllowMultiRowEdit="True" >

        <MasterTableView CommandItemDisplay="TopAndBottom" DataSourceID="odsBudgetAccounts" CommandItemSettings-ShowAddNewRecordButton="false" DataKeyNames="ID" Width="880px"
            GroupLoadMode="Server" NoMasterRecordsText="<%$ Resources:MainGrid , NoMasterRecordsText %>"
            NoDetailRecordsText="<%$ Resources:MainGrid , NoMasterRecordsText %>" EditMode="InPlace" >

            <Columns>

                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton" Visible="false">
                    <ItemStyle CssClass="MyImageButton" Width="50px" HorizontalAlign="Center" VerticalAlign="Middle" />
                    <HeaderStyle Width="50px" HorizontalAlign="Center" VerticalAlign="Middle" />
                </telerik:GridEditCommandColumn>

                <telerik:GridBoundColumn SortExpression="ID" Visible="false" HeaderButtonType="TextButton"
                    DataField="ID" UniqueName="ID" ReadOnly="true">
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="AccountNumber" meta:ResourceKey="gbcAccountNum"
                    SortExpression="AccountNumber" UniqueName="AccountNumber" ReadOnly="true" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="<%$ Resources:SystemResource, rcbAccount %>" SortExpression="<%$ Resources:SystemResource, rcbAccount %>"
                    UniqueName="AccountName" Visible="true" ReadOnly="true" meta:ResourceKey="gbcAccountName">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="AccountNameEn" SortExpression="AccountNameEn"
                    UniqueName="AccountNameEn" ReadOnly="true" Visible="false">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="AccountNameAr" SortExpression="AccountNameAr"
                    UniqueName="AccountNameAr" ReadOnly="true" Visible="false">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
                </telerik:GridBoundColumn>

                <telerik:GridNumericColumn DataField="Amount" SortExpression="Amount"
                    UniqueName="Amount" Visible="true" meta:ResourceKey="gbcAmount" DataFormatString="{0:###,###.##}" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn SortExpression="IncreaseAmount" DataFormatString="{0:###,###.##}" ReadOnly="true"
                    DataField="IncreaseAmount" UniqueName="IncreaseAmount" meta:ResourceKey="gbcIncreaseAmount" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn SortExpression="Transfer" DataFormatString="{0:###,###.##}" ReadOnly="true"
                    DataField="Transfer" UniqueName="Transfer" meta:ResourceKey="gbcTransfer" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                </telerik:GridNumericColumn>

                <telerik:GridNumericColumn SortExpression="Total" DataFormatString="{0:###,###.##}"
                    DataField="Total" UniqueName="Total" meta:ResourceKey="gbcTotal" ReadOnly="true" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                </telerik:GridNumericColumn>

                <%--<telerik:GridCalculatedColumn DataFields="Amount, IncreaseAmount" meta:resourcekey="gbcTotal" Expression="{0}+{1}"  DataFormatString="{0:###,###.##}"
                    SortExpression="Total" UniqueName="Total" Visible="True" AllowSorting="false" AllowFiltering="false" Display="true" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </telerik:GridCalculatedColumn>--%>

                <%--<telerik:GridTemplateColumn meta:resourcekey="gbcTotal" SortExpression="Total" 
                    UniqueName="Total" Visible="True" AllowFiltering="false" Display="true" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <EditItemTemplate>
                        <asp:Label ID="lblTotal" runat="server" Text='<%# Bind("Total") %>' ></asp:Label>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>--%>

                <telerik:GridNumericColumn SortExpression="LinkAmount" DataFormatString="{0:###,###.##}"
                    DataField="LinkAmount" UniqueName="LinkAmount" meta:ResourceKey="gbcLinkAmount" ReadOnly="true" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"  />
                </telerik:GridNumericColumn>

                <telerik:GridCalculatedColumn DataFields="Amount, IncreaseAmount" meta:resourcekey="gbcSpentAmount" Expression="{0}+{1}-{0}"  DataFormatString="{0:###,###.##}"
                    SortExpression="SpentAmount" UniqueName="SpentAmount" Visible="True" AllowSorting="false" AllowFiltering="false">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </telerik:GridCalculatedColumn>

                <telerik:GridCalculatedColumn DataFields="Amount, IncreaseAmount" meta:resourcekey="gbcLeftAmount" Expression="{0}-({0}+{1}-{0})"  DataFormatString="{0:###,###.##}"
                    SortExpression="LeftAmount" UniqueName="LeftAmount" Visible="True" AllowSorting="false" AllowFiltering="false" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </telerik:GridCalculatedColumn>

            </Columns>

            </MasterTableView>
            <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"></ExportSettings>
            <GroupingSettings CaseSensitive="false" />
            <ClientSettings  >
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
            </telerik:RadGrid>

        

        <asp:HiddenField ID="hdnBudgetID" runat="server" />



        <%--<sds:SessionDataSource ID="sdsBudgetAccounts" runat="server" ClearSessionOnInitialLoad="True"
        ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
        DeleteCommand="Delete From [BudgetAccounts] WHERE [ID] = ? "
        InsertCommand="INSERT INTO [BudgetAccounts] ( BudgetID , Amount , IncreaseAmount , Transfer , LinkAmount , AccountID ) VALUES (?, ?, ?, ?, ?, ?)"
        SelectCommand="select BudgetAccounts.ID,
	                    BudgetAccounts.BudgetID,
	                    BudgetAccounts.Amount,
	                    BudgetAccounts.IncreaseAmount,
	                    BudgetAccounts.Transfer,
	                    BudgetAccounts.LinkAmount,
	                    Accounts.ID as AccountID,
	                    Accounts.AccountNumber,
	                    Accounts.AccountName
	                    from BudgetAccounts 
	                    right outer join Accounts ON BudgetAccounts.AccountID = Accounts.ID 
	                    left outer join Budget ON Budget.ID = BudgetAccounts.BudgetID 
	                    Where BudgetAccounts.BudgetID = @BudgetID Or BudgetAccounts.BudgetID is NULL
                        order by BudgetAccounts.ID "
        
        UpdateCommand="Update BudgetAccounts
	                    set  BudgetID = ? , Amount = ? , IncreaseAmount = ? , Transfer = ? , LinkAmount = ? , AccountID = ?" 
        SessionKey="System.Web.UI.Page_sdsBudgetAccounts">
                    
        <SelectParameters>
         <asp:ControlParameter ControlID="hdnBudgetID" Name="BudgetID" PropertyName="Value" DefaultValue="0" />
        </SelectParameters>

        </sds:SessionDataSource>--%>




        <br /><br />

               <asp:LinkButton ID="btnSave" ValidationGroup="valBudget" runat="server" Font-Bold="false" meta:ResourceKey="btnSave" Font-Size="Medium" CssClass="menuitem_green" />
               &nbsp;
               <%--<asp:LinkButton ID="btnCancel" runat="server" Font-Bold="false" meta:ResourceKey="btnCancel" Font-Size="Medium" CssClass="menuitem_red" />--%>



    <asp:ObjectDataSource ID="odsBudgetAccounts" runat="server" 
    SelectMethod="QueryDatabase" TypeName="DBBudgetAccountsSP" >
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="QueryType" Type="Object" />
            <asp:Parameter DefaultValue="RtvBudgetAccountsByBudgetID" Name="Operation" Type="String" />
            <asp:Parameter Name="ID" Type="String" />
            <asp:Parameter Name="BudgetID" Type="String" />
            <asp:Parameter Name="AccountNo" Type="String" />
            <asp:Parameter Name="Amount" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>


</asp:Content>

